//
//  DisplayViewController.m
//  sdkdemo-iOS
//
//  Created by 范保莹 on 2018/6/4.
//  Copyright © 2018年 sdkdemo-iOS. All rights reserved.
//

#import "DisplayViewController.h"

#import "CardReaderTableViewCell.h"

#import "MPCardReadInfoModel.h"
#import "MPDisplayContentModel.h"

#import "DisplayManager.h"

@interface DisplayViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(strong,nonatomic)UILabel *titleLab;

@property(strong, nonatomic)UIView *titleContentView;

@property(strong, nonatomic)UIView *contentView;

@property(strong, nonatomic)UIView *contentListView;

@property(strong,nonatomic)UITableView *myTableView;

@property(strong,nonatomic)NSMutableArray *dataArr;

@end

@implementation DisplayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    [self titleContent];
    
    [self content];
    
    [self contentList];
    
}

- (void)titleContent{
    
    self.titleContentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH*5/6, 80)];
    [self.view addSubview:_titleContentView];
    
    UIButton *contentBtn = [[UIButton alloc]initWithFrame:CGRectMake(15, 15, (SCREEN_WIDTH*5/6-3)/5-5, 30)];
    contentBtn.backgroundColor = [UIColor colorWithRed:105/255.0 green:150/255.0 blue:200/255.0 alpha:1];
    contentBtn.layer.cornerRadius = 5.0;
    contentBtn.clipsToBounds = YES;
    contentBtn.titleLabel.font = [UIFont systemFontOfSize:12.0];
    [contentBtn setTitle:@"单元测试" forState:0];
    [contentBtn addTarget:self action:@selector(contentBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.titleContentView addSubview:contentBtn];
    
    self.titleLab = [[UILabel alloc]initWithFrame:CGRectMake((SCREEN_WIDTH*5/6-3)/5, 10, (SCREEN_WIDTH*5/6-3)*3/5, 40)];
    self.titleLab.text = _titleStr;
    self.titleLab.textColor = bgColor;
    self.titleLab.textAlignment = NSTextAlignmentCenter;
    self.titleLab.font = [UIFont systemFontOfSize:16.0];
    [self.titleContentView addSubview:_titleLab];

    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 60, SCREEN_WIDTH*5/6-3, 5)];
    lab.backgroundColor = bgColor;
    [self.view addSubview:lab];
}

- (void)content{
    
    self.contentView = [[UIView alloc]initWithFrame:CGRectMake(0, 70, SCREEN_WIDTH*5/6, 70)];
    [self.view addSubview:_contentView];
    
    UILabel *titleLab1 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH*5/18, 0, SCREEN_WIDTH*5/18, 30)];
    titleLab1.text = @"单元测试";
    titleLab1.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:titleLab1];
    
    NSArray *titleArr = @[@"待测接口",@"接口功能",@"入参参数",@"预期结果",@"实际结果",@"是否通过"];
    for (int i = 0; i < titleArr.count; i ++) {
        int cont = (SCREEN_WIDTH*5/6-3)*i/6;
        
        UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake(cont, 30, (SCREEN_WIDTH*5/6-3)/6, 40)];
        titleLab.text = titleArr[i];
        titleLab.textColor = ALLTextColor;
        titleLab.font = [UIFont systemFontOfSize:14.0];
        titleLab.numberOfLines = 0;
        titleLab.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:titleLab];
        
    }
    
    
}

- (void)contentList{
    
    self.contentListView = [[UIView alloc]initWithFrame:CGRectMake(0, 140, SCREEN_WIDTH*5/6, SCREEN_HEIGHT-140)];
    [self.view addSubview:_contentListView];
    
    self.myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH*5/6, SCREEN_HEIGHT-140)];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.contentListView addSubview:_myTableView];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _dataArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 60;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CardReaderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    if (cell == nil) {
        cell = [[CardReaderTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    cell.testPortLab.text = [_dataArr[indexPath.row] objectForKey:@"one"];
    cell.portFunctionLab.text = [_dataArr[indexPath.row] objectForKey:@"two"];
    cell.parameterLab.text = [_dataArr[indexPath.row] objectForKey:@"third"];
    cell.expectResultLab.text = [_dataArr[indexPath.row] objectForKey:@"four"];
    cell.realityResultLab.text = [_dataArr[indexPath.row] objectForKey:@"five"];
    cell.isPassLab.text = [_dataArr[indexPath.row] objectForKey:@"sex"];
    //
    return cell;
    
}

//单元测试点击事件
- (void)contentBtn:(UIButton *)sender{
    
    self.dataArr = [[NSMutableArray alloc]initWithCapacity:0];
    
    //    DISPLAY模块
    [self display];
    
}
//    DISPLAY模块
- (void)display{
    
    //    子线程
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [DisplayManager requestCleanScreen];
        [self dataList:@"requestCleanScreen" withTwo:@"清除电子屏幕显示内容" withThird:@"" withFour:@"成功" withFive:@"成功" withSex:@"1"];
        
        [NSThread sleepForTimeInterval:1.0];
        [self onShowMultiLine:nil];
        
        [NSThread sleepForTimeInterval:1.0];
        [self displayQRCode:@"123456"];
        
    });
}

- (void)onShowMultiLine:(NSArray<MPDisplayContentModel*>*)entityList{
    
    [DisplayManager onShowMultiLine:entityList];
    [self dataList:@"onShowMultiLine" withTwo:@"在电子屏幕显示内容" withThird:@"无参数" withFour:@"成功" withFive:@"成功" withSex:@"1"];
}

- (void)displayQRCode:(NSString*)qrCode{
    
    [DisplayManager displayQRCode:qrCode handle:^(OprResEnum status) {
        [self dataList:@"displayQRCode" withTwo:@"在屏幕显示二维码" withThird:@"无参数" withFour:@"成功" withFive:@"成功" withSex:@"1"];
    }];
}

- (void)dataList:(NSString *)one withTwo:(NSString *)two withThird:(NSString *)third withFour:(NSString *)four withFive:(NSString *)five withSex:(NSString *)sex{
    
    NSMutableDictionary *dic2 = [NSMutableDictionary dictionary];
    dic2[@"one"] = one;
    dic2[@"two"] = two;
    dic2[@"third"] = third;
    dic2[@"four"] = four;
    dic2[@"five"] = five;
    dic2[@"sex"] = sex;
    [_dataArr addObject:dic2];
    
    NSLog(@"%@",dic2);
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        [_myTableView reloadData];
        
    });
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
